package very.util.scalikejdbc
import skinny.Pagination

case class PaginationFix(pageSize: Int, pageNo: Int)

object PaginationFix {

  def apply(pageNo: Int): PaginationFix = PaginationFix(20, pageNo)

  def from(map: Map[String, Seq[String]]): Pagination = {
    PaginationFix(
      map.get("pageSize").flatMap(_.headOption.map(_.toInt)).getOrElse(20),
      map.get("page").flatMap(_.headOption.map(_.toInt)).getOrElse(1)
    )
  }
  implicit def toPagination(p: PaginationFix): Pagination = {
    Pagination(if (p.pageSize > 20) 20 else p.pageSize, if (p.pageNo < 1) 1 else p.pageNo)
  }
}
